<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-lineleader.h</h1>  </div>
</div>
<div class="contents">
<a href="mindsensors-lineleader_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*!@addtogroup mindsensors</span>
<a name="l00002"></a>00002 <span class="comment"> * @{</span>
<a name="l00003"></a>00003 <span class="comment"> * @defgroup msll LineLeader Sensor</span>
<a name="l00004"></a>00004 <span class="comment"> * LineLeader Sensor</span>
<a name="l00005"></a>00005 <span class="comment"> * @{</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="comment">/*</span>
<a name="l00009"></a>00009 <span class="comment"> * $Id: mindsensors-lineleader.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#ifndef __MSLL_H__</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define __MSLL_H__</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00015"></a>00015 <span class="comment">/** \file mindsensors-lineleader.h</span>
<a name="l00016"></a>00016 <span class="comment"> * \brief Mindsensors Line Tracking Sensor</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * mindsensors-lineleader.h provides an API for the Mindsensors Line Tracking Sensor.</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> * Changelog:</span>
<a name="l00021"></a>00021 <span class="comment"> *  - 0.1 Initial       TFR&lt;br&gt;</span>
<a name="l00022"></a>00022 <span class="comment"> *  - 0.2 Added ability to read multi-ubyte values for raw, white and black thresholds.&lt;br&gt;</span>
<a name="l00023"></a>00023 <span class="comment"> *  - 0.3 Added PID factor registers (Read/Write), Added new commands &#39;S&#39;napShot, &#39;R&#39;eset,</span>
<a name="l00024"></a>00024 <span class="comment"> *      and changed function and method names to be more C++ like.&lt;br&gt;</span>
<a name="l00025"></a>00025 <span class="comment"> *  - 0.4 Modified to conform to new &quot;naming standard&quot; and be part of the driver suite.&lt;br&gt;</span>
<a name="l00026"></a>00026 <span class="comment"> *       changed all (int) casts to ubyteToInt() calls.&lt;br&gt;</span>
<a name="l00027"></a>00027 <span class="comment"> *       all direct I2C calls changed to readI2C() and writeI2C() calls.</span>
<a name="l00028"></a>00028 <span class="comment"> *  - 0.5 Bug in LLreadSteering fixed</span>
<a name="l00029"></a>00029 <span class="comment"> *  - 0.6 Added LLreadSensorUncalibrated</span>
<a name="l00030"></a>00030 <span class="comment"> *</span>
<a name="l00031"></a>00031 <span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<a name="l00032"></a>00032 <span class="comment"> *</span>
<a name="l00033"></a>00033 <span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<a name="l00034"></a>00034 <span class="comment"></span>
<a name="l00035"></a>00035 <span class="comment"> * \author Thom Roach</span>
<a name="l00036"></a>00036 <span class="comment"> * \author Xander Soldaat (version 0.4+)</span>
<a name="l00037"></a>00037 <span class="comment"> * \date 29 October 2009</span>
<a name="l00038"></a>00038 <span class="comment"> * \version 0.6</span>
<a name="l00039"></a>00039 <span class="comment"> * \example mindsensors-lineleader-test2.c</span>
<a name="l00040"></a>00040 <span class="comment"> * \example mindsensors-lineleader-test3.c</span>
<a name="l00041"></a>00041 <span class="comment"> * \example mindsensors-lineleader-test4.c</span>
<a name="l00042"></a>00042 <span class="comment"> */</span>
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="preprocessor">#pragma systemFile</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span>
<a name="l00046"></a>00046 <span class="preprocessor">#ifndef __COMMON_H__</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">        #include &quot;<a class="code" href="common_8h.html" title="Commonly used functions used by drivers.">common.h</a>&quot;</span>
<a name="l00048"></a>00048 <span class="preprocessor">#endif</span>
<a name="l00049"></a>00049 <span class="preprocessor"></span>
<a name="l00050"></a>00050 <span class="comment">//*******************************************************************************</span>
<a name="l00051"></a>00051 <span class="comment">// REGISTER LOCATIONS AND COMMANDS for the Line Leader Sensor</span>
<a name="l00052"></a>00052 <span class="comment">//*******************************************************************************</span>
<a name="l00053"></a><a class="code" href="group__msll.html#gacf9f00f667e856b91dd8c12fbfed42a4">00053</a> <span class="preprocessor">#define LL_I2C_ADDR             0x02  </span><span class="comment">/*!&lt; I2C address used by the LL */</span>
<a name="l00054"></a><a class="code" href="group__msll.html#ga746196c5de3e53dc5725aab5371eb93e">00054</a> <span class="preprocessor">#define LL_CMD_REG              0x41  </span><span class="comment">/*!&lt; Register used for issuing commands */</span>
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="group__msll.html#ga71b745ac640e505f3d1b16c9676d80b7">00056</a> <span class="preprocessor">#define LL_SETPOINT       0x45  </span><span class="comment">/*!&lt; average value considered center of line (def=45) */</span>
<a name="l00057"></a><a class="code" href="group__msll.html#gacc1f77e986571b86ba33032b50cb455f">00057</a> <span class="preprocessor">#define LL_KP_VALUE                     0x46  </span><span class="comment">/*!&lt; P value of PID control */</span>
<a name="l00058"></a><a class="code" href="group__msll.html#ga828d2ade2893ef6fe4d3da8dcb5085c7">00058</a> <span class="preprocessor">#define LL_KI_VALUE                     0X47  </span><span class="comment">/*!&lt; I value of PID control */</span>
<a name="l00059"></a><a class="code" href="group__msll.html#gaa6ab601259447a08cb199b0c93c4f398">00059</a> <span class="preprocessor">#define LL_KD_VALUE                     0X48  </span><span class="comment">/*!&lt; D value of PID control */</span>
<a name="l00060"></a><a class="code" href="group__msll.html#gada9c6b1576eca1d325b85c40cc7855af">00060</a> <span class="preprocessor">#define LL_KP_FACTOR      0x61  </span><span class="comment">/*!&lt; P factor for P value of PID control */</span>
<a name="l00061"></a><a class="code" href="group__msll.html#ga1b438aeb7ddc87573bfd9c24ca42458a">00061</a> <span class="preprocessor">#define LL_KI_FACTOR      0X62  </span><span class="comment">/*!&lt; I factor for I value of PID control */</span>
<a name="l00062"></a><a class="code" href="group__msll.html#ga92eb450c20cd134bc90ff6ff2f6347a1">00062</a> <span class="preprocessor">#define LL_KD_FACTOR      0X63  </span><span class="comment">/*!&lt; D factor for D value of PID control */</span>
<a name="l00063"></a>00063 
<a name="l00064"></a><a class="code" href="group__msll.html#ga85a98047cb31c3c285f3a6d3f4db060a">00064</a> <span class="preprocessor">#define LL_READ_STEERING        0x42  </span><span class="comment">/*!&lt; steering value for simple mode line following */</span>
<a name="l00065"></a><a class="code" href="group__msll.html#ga1638f7ba693960a75abf313a7344a9ee">00065</a> <span class="preprocessor">#define LL_READ_AVERAGE         0X43  </span><span class="comment">/*!&lt; weighted average value for all sensors in array */</span>
<a name="l00066"></a><a class="code" href="group__msll.html#ga12ad5be14508319b2bfc8290b41ad886">00066</a> <span class="preprocessor">#define LL_READ_RESULT          0X44  </span><span class="comment">/*!&lt; 1 or 0 for line or no line for all 8 sensors */</span>
<a name="l00067"></a><a class="code" href="group__msll.html#ga5638e005055b1df5e595734a42c4b179">00067</a> <span class="preprocessor">#define LL_SENSOR_RAW           0X49  </span><span class="comment">/*!&lt; ubyte array (8) with raw value for each sensor */</span>
<a name="l00068"></a><a class="code" href="group__msll.html#ga253d9d0e7d4ea08b11dc777088490bc1">00068</a> <span class="preprocessor">#define LL_WHITE_LIMIT          0X51  </span><span class="comment">/*!&lt; ubyte array (8) with raw value of white calibration for each sensor */</span>
<a name="l00069"></a><a class="code" href="group__msll.html#ga746144b962d3a52cbf7d507c6be2d4c2">00069</a> <span class="preprocessor">#define LL_BLACK_LIMIT          0X59  </span><span class="comment">/*!&lt; ubyte array (8) with raw value of black calibration for each sensor */</span>
<a name="l00070"></a><a class="code" href="group__msll.html#gad0456ad794e3fa5deb85f288315c4d49">00070</a> <span class="preprocessor">#define LL_SENSOR_UNCAL   0x74  </span><span class="comment">/*!&lt; ubyte array (16) with uncalibrated sensor data */</span>
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">00072</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>;       <span class="comment">/*!&lt; Array to hold I2C command data */</span>
<a name="l00073"></a><a class="code" href="group__msll.html#ga2be29d118be70da80c5b5b0ddeaad572">00073</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group__msll.html#ga2be29d118be70da80c5b5b0ddeaad572">LL_I2CReply</a>;         <span class="comment">/*!&lt; Array to hold I2C reply data */</span>
<a name="l00074"></a><a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">00074</a> ubyte <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00075"></a>00075 
<a name="l00076"></a>00076 <span class="comment">//*******************************************************************************</span>
<a name="l00077"></a>00077 <span class="comment">// PUBLIC Line Leader functions</span>
<a name="l00078"></a>00078 <span class="comment">//*******************************************************************************</span>
<a name="l00079"></a>00079 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga1db790809590cad8e206870a3e814bbc">LLinit</a>(tSensors link);                                         <span class="comment">/*!&lt; Set up Line Leader sensor type */</span>
<a name="l00080"></a>00080 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga3b5fbe1abe3eb0889c9fb30ff7d7c01b">LLwakeUp</a>(tSensors link);                                                       <span class="comment">/*!&lt; Wake sensor from sleep mode */</span>
<a name="l00081"></a>00081 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga2bbf71694ef338dab472618a6442c429">LLsleep</a>(tSensors link);                                                        <span class="comment">/*!&lt; Sleep to conserve power when not in use */</span>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#gad94d0f9fc1c628d9e1a8fe598d64302b">LLinvertLineColor</a>(tSensors link);                    <span class="comment">/*!&lt; Inverts detected line color */</span>
<a name="l00084"></a>00084 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#gaefd78fa2909cf1b98961ebf3e845e7b1">LLresetLineColor</a>(tSensors link);                     <span class="comment">/*!&lt; Resets line color to dark on light bkgrnd */</span>
<a name="l00085"></a>00085 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga71dbb04b90ec6f5c90c34b5db4c638d5">LLtakeSnapshot</a>(tSensors link);                       <span class="comment">/*!&lt; takes a snapshot to determine line color */</span>
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga780835bc9c4f659670ac26a992896ac7">LLcalWhite</a>(tSensors link);                           <span class="comment">/*!&lt; Set white threshold for light area */</span>
<a name="l00088"></a>00088 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga9441ee5facb3b5a93d35fd47624b996c">LLcalBlack</a>(tSensors link);                           <span class="comment">/*!&lt; Set black threshold for dark area */</span>
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga48b8ab2daaa7afede45d1501933824f0">LLsetPoint</a>(tSensors link, ubyte data);                <span class="comment">/*!&lt; WRITE mid-point or center of line value */</span>
<a name="l00091"></a>00091 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga48b8ab2daaa7afede45d1501933824f0">LLsetPoint</a>(tSensors link);                            <span class="comment">/*!&lt; READ SetPoint value */</span>
<a name="l00092"></a>00092 
<a name="l00093"></a>00093 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga023144b86129e6828fa94b757016065f">LLsetKp</a>(tSensors link, ubyte data, ubyte factor);      <span class="comment">/*!&lt; WRITE Kp value */</span>
<a name="l00094"></a>00094 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#gaee40b167cd0fcb978895964cbf1d478b">LLreadKp</a>(tSensors link);                              <span class="comment">/*!&lt; READ Kp value */</span>
<a name="l00095"></a>00095 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga49001b6744c482e856fde7283e711e75">LLreadKpFactor</a>(tSensors link);                        <span class="comment">/*!&lt; READ p factor value */</span>
<a name="l00096"></a>00096 
<a name="l00097"></a>00097 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga9ca02184d0ee468b2fdd7e537654d7d3">LLsetKi</a>(tSensors link, ubyte data, ubyte factor);      <span class="comment">/*!&lt; WRITE Ki value */</span>
<a name="l00098"></a>00098 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#gac090fcc45f5a6c53c94a31d82b61924e">LLreadKi</a>(tSensors link);                              <span class="comment">/*!&lt; READ Ki value */</span>
<a name="l00099"></a>00099 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga49d4b5bed7383b1ca1d3b45860dec496">LLreadKiFactor</a>(tSensors link);                        <span class="comment">/*!&lt; READ i factor value */</span>
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga5e59a3463a3e8b2665e6b3555da8f93d">LLsetKd</a>(tSensors link, ubyte data, ubyte factor);      <span class="comment">/*!&lt; WRITE Kd value */</span>
<a name="l00102"></a>00102 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga2d9d9c3cfd5dd9be7bb4f9e57408fbd7">LLreadKd</a>(tSensors link);                              <span class="comment">/*!&lt; READ Kd value */</span>
<a name="l00103"></a>00103 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga8d6b35d47284e3ee40b68a490ad71ced">LLreadKdFactor</a>(tSensors link);                        <span class="comment">/*!&lt; READ d factor value */</span>
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga5c46604095f77a86983b7aeaf22200dc">LLreadSteering</a>(tSensors link);                        <span class="comment">/*!&lt; Read internally calculated steering value */</span>
<a name="l00106"></a>00106 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga9a35e15add220ed326ca7520ffe65e6c">LLreadAverage</a>(tSensors link);                         <span class="comment">/*!&lt; Read weighted sensor array average value */</span>
<a name="l00107"></a>00107 <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga7dd78212c25b63c0349b8f4c61e11e1b">LLreadResult</a>(tSensors link);                                            <span class="comment">/*!&lt; Read boolean sensor array values for all sensors */</span>
<a name="l00108"></a>00108 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga60491a411576c00b70909e1f295919db">LLreadSensorRaw</a>(tSensors link, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pMsg);    <span class="comment">/*!&lt; Return array of raw light values (8 bytes) */</span>
<a name="l00109"></a>00109 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga9c243c81526226b5666b5d14a5fc8e59">LLreadSensorUncalibrated</a> (tSensors link, <a class="code" href="group__common.html#ga79eb917b5a56f0d0e7cf94886c6ac25c">tIntArray</a> &amp;sensorValues);  <span class="comment">/*!&lt; Return array of raw uncalibrated light values (8 ints) */</span>
<a name="l00110"></a>00110 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga1aaffb6d171becb4d2cb516077417691">LLreadWhiteThresh</a>(tSensors link, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pMsg);  <span class="comment">/*!&lt; Return array of white thresholds (8 bytes) */</span>
<a name="l00111"></a>00111 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#gafe57238ecefde4bc4992c0ff8c77a896">LLreadBlackThresh</a>(tSensors link, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pMsg);  <span class="comment">/*!&lt; Return array of black thresholds (8 bytes) */</span>
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 <span class="comment">//*******************************************************************************</span>
<a name="l00114"></a>00114 <span class="comment">// INTERNAL USE ONLY - Line Leader functions - used by the above</span>
<a name="l00115"></a>00115 <span class="comment">//*******************************************************************************</span>
<a name="l00116"></a>00116 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(tSensors link, ubyte cmd);                      <span class="comment">/*!&lt; Send a command to the Line Leader */</span>
<a name="l00117"></a>00117 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(tSensors link, ubyte regToWrite, ubyte data);  <span class="comment">/*!&lt; Write to a Line Leader Register */</span>
<a name="l00118"></a>00118 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(tSensors link, ubyte regToRead, ubyte &amp;retval); <span class="comment">/*!&lt; Read one ubyte from a Line Leader Register */</span>
<a name="l00119"></a>00119 <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(tSensors link, ubyte regToRead, <span class="keywordtype">int</span> numBytes, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pDataMsg);  <span class="comment">/*!&lt; Read data from a Line Leader Register */</span>
<a name="l00120"></a>00120 
<a name="l00121"></a>00121 <span class="comment">//*******************************************************************************</span>
<a name="l00122"></a>00122 <span class="comment">// FUNCTION DEFINITIONS</span>
<a name="l00123"></a>00123 <span class="comment">//*******************************************************************************</span><span class="comment"></span>
<a name="l00124"></a>00124 <span class="comment">/**</span>
<a name="l00125"></a>00125 <span class="comment"> * This function sends a command to the lineleader over I2C.</span>
<a name="l00126"></a>00126 <span class="comment"> *</span>
<a name="l00127"></a>00127 <span class="comment"> * Note: this is an internal function and should not be called directly.</span>
<a name="l00128"></a>00128 <span class="comment"> * @param link the sensor port number</span>
<a name="l00129"></a>00129 <span class="comment"> * @param cmd the command to be sent</span>
<a name="l00130"></a>00130 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00131"></a>00131 <span class="comment"></span>
<a name="l00132"></a>00132 <span class="comment">PRELIMINARY COMMANDS FROM NXC LIB CODE</span>
<a name="l00133"></a>00133 <span class="comment"> - A American frequency compensation</span>
<a name="l00134"></a>00134 <span class="comment"> - B for black calibration</span>
<a name="l00135"></a>00135 <span class="comment"> - D sensor power down</span>
<a name="l00136"></a>00136 <span class="comment"> - E European frequency compensation</span>
<a name="l00137"></a>00137 <span class="comment"> - I invert line color</span>
<a name="l00138"></a>00138 <span class="comment"> - P power on sensor</span>
<a name="l00139"></a>00139 <span class="comment"> - R reset line color to dark</span>
<a name="l00140"></a>00140 <span class="comment"> - S snapshot to determine line color</span>
<a name="l00141"></a>00141 <span class="comment"> - U Universal frequency compensation (default)</span>
<a name="l00142"></a>00142 <span class="comment"> - S setpoint based on snapshot (automatically set&#39;s invert if needed)</span>
<a name="l00143"></a>00143 <span class="comment"> - W White balance</span>
<a name="l00144"></a>00144 <span class="comment"> */</span>
<a name="l00145"></a><a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">00145</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(tSensors link, ubyte cmd) {
<a name="l00146"></a>00146   <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[0] = 3;             <span class="comment">// Message size</span>
<a name="l00147"></a>00147   <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[1] = <a class="code" href="group__msll.html#gacf9f00f667e856b91dd8c12fbfed42a4">LL_I2C_ADDR</a>;   <span class="comment">// I2C Address</span>
<a name="l00148"></a>00148   <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[2] = <a class="code" href="group__msll.html#ga746196c5de3e53dc5725aab5371eb93e">LL_CMD_REG</a>;    <span class="comment">// Register used for issuing commands</span>
<a name="l00149"></a>00149   <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[3] = cmd;           <span class="comment">// Command to be executed</span>
<a name="l00150"></a>00150 
<a name="l00151"></a>00151   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>);
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 <span class="comment"></span>
<a name="l00155"></a>00155 <span class="comment">/**</span>
<a name="l00156"></a>00156 <span class="comment"> * This function writes data to a register in the LL sensor over I2C.</span>
<a name="l00157"></a>00157 <span class="comment"> *</span>
<a name="l00158"></a>00158 <span class="comment"> * Note: this is an internal function and should not be called directly.</span>
<a name="l00159"></a>00159 <span class="comment"> * @param link the sensor port number</span>
<a name="l00160"></a>00160 <span class="comment"> * @param regToWrite the register to write to</span>
<a name="l00161"></a>00161 <span class="comment"> * @param data the value to write to the register</span>
<a name="l00162"></a>00162 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00163"></a>00163 <span class="comment"> */</span>
<a name="l00164"></a>00164 
<a name="l00165"></a><a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">00165</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(tSensors link, ubyte regToWrite, ubyte data) {
<a name="l00166"></a>00166 
<a name="l00167"></a>00167   memset(<a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00168"></a>00168         <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[0] = 3;             <span class="comment">// Message size</span>
<a name="l00169"></a>00169   <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[1] = <a class="code" href="group__msll.html#gacf9f00f667e856b91dd8c12fbfed42a4">LL_I2C_ADDR</a>;   <span class="comment">// I2C Address</span>
<a name="l00170"></a>00170   <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[2] = regToWrite;    <span class="comment">// Register address to set</span>
<a name="l00171"></a>00171   <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[3] = data;          <span class="comment">// value to place in register address</span>
<a name="l00172"></a>00172 
<a name="l00173"></a>00173   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>);
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175 
<a name="l00176"></a>00176 <span class="comment"></span>
<a name="l00177"></a>00177 <span class="comment">/**</span>
<a name="l00178"></a>00178 <span class="comment"> * This function reads one ubyte from a register in the LL sensor over I2C.</span>
<a name="l00179"></a>00179 <span class="comment"> *</span>
<a name="l00180"></a>00180 <span class="comment"> * Note: this is an internal function and should not be called directly.</span>
<a name="l00181"></a>00181 <span class="comment"> * @param link the sensor port number</span>
<a name="l00182"></a>00182 <span class="comment"> * @param regToRead the register to read from</span>
<a name="l00183"></a>00183 <span class="comment"> * @param retval the ubyte in which to store the reply</span>
<a name="l00184"></a>00184 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00185"></a>00185 <span class="comment"> */</span>
<a name="l00186"></a><a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">00186</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(tSensors link, ubyte regToRead, ubyte &amp;retval) {
<a name="l00187"></a>00187         memset(<a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>));
<a name="l00188"></a>00188         <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[0] =  2;
<a name="l00189"></a>00189         <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[1] =  <a class="code" href="group__msll.html#gacf9f00f667e856b91dd8c12fbfed42a4">LL_I2C_ADDR</a>;
<a name="l00190"></a>00190         <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[2] =  regToRead;
<a name="l00191"></a>00191 
<a name="l00192"></a>00192   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>, <a class="code" href="group__msll.html#ga2be29d118be70da80c5b5b0ddeaad572">LL_I2CReply</a>, 1))
<a name="l00193"></a>00193     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00194"></a>00194 
<a name="l00195"></a>00195   retval = (int)<a class="code" href="group__msll.html#ga2be29d118be70da80c5b5b0ddeaad572">LL_I2CReply</a>[0];
<a name="l00196"></a>00196 
<a name="l00197"></a>00197   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200 <span class="comment"></span>
<a name="l00201"></a>00201 <span class="comment">/**</span>
<a name="l00202"></a>00202 <span class="comment"> * This function reads multiple bytes from a register in the LL sensor over I2C.</span>
<a name="l00203"></a>00203 <span class="comment"> *</span>
<a name="l00204"></a>00204 <span class="comment"> * Note: this is an internal function and should not be called directly.</span>
<a name="l00205"></a>00205 <span class="comment"> * @param link the sensor port number</span>
<a name="l00206"></a>00206 <span class="comment"> * @param regToRead the register to read from</span>
<a name="l00207"></a>00207 <span class="comment"> * @param numBytes the number of bytes to read</span>
<a name="l00208"></a>00208 <span class="comment"> * @param pDataMsg tByteArray to store reply</span>
<a name="l00209"></a>00209 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00210"></a>00210 <span class="comment"> */</span>
<a name="l00211"></a><a class="code" href="group__msll.html#gac5d314850c7f4192dd2e7c2307f96f6b">00211</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(tSensors link, ubyte regToRead, <span class="keywordtype">int</span> numBytes, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pDataMsg) {
<a name="l00212"></a>00212         memset(<a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00213"></a>00213         memset(pDataMsg, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00214"></a>00214 
<a name="l00215"></a>00215         <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[0] =  2;
<a name="l00216"></a>00216         <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[1] =  <a class="code" href="group__msll.html#gacf9f00f667e856b91dd8c12fbfed42a4">LL_I2C_ADDR</a>;
<a name="l00217"></a>00217         <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>[2] =  regToRead;
<a name="l00218"></a>00218 
<a name="l00219"></a>00219 
<a name="l00220"></a>00220   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group__msll.html#ga8dd01df4fc54bdb09a4d0324e0a52b14">LL_I2CRequest</a>, <a class="code" href="group__msll.html#ga2be29d118be70da80c5b5b0ddeaad572">LL_I2CReply</a>, numBytes))
<a name="l00221"></a>00221     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00222"></a>00222 
<a name="l00223"></a>00223   <span class="comment">// copy the result into the array to be returned.</span>
<a name="l00224"></a>00224   memcpy(pDataMsg, <a class="code" href="group__msll.html#ga2be29d118be70da80c5b5b0ddeaad572">LL_I2CReply</a>, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00225"></a>00225   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00226"></a>00226 }
<a name="l00227"></a>00227 
<a name="l00228"></a>00228 <span class="comment"></span>
<a name="l00229"></a>00229 <span class="comment">/**</span>
<a name="l00230"></a>00230 <span class="comment"> * This function initializes the line leader to prepare for use.</span>
<a name="l00231"></a>00231 <span class="comment"> * Issuing a command also wakes the line leader as needed.</span>
<a name="l00232"></a>00232 <span class="comment"> * @param link the sensor port number</span>
<a name="l00233"></a>00233 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00234"></a>00234 <span class="comment"> */</span>
<a name="l00235"></a><a class="code" href="group__msll.html#ga1db790809590cad8e206870a3e814bbc">00235</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga1db790809590cad8e206870a3e814bbc">LLinit</a>(tSensors link) {
<a name="l00236"></a>00236         nI2CBytesReady[link] = 0;
<a name="l00237"></a>00237         SensorType[link] = sensorI2CCustom9V;
<a name="l00238"></a>00238         <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga3b5fbe1abe3eb0889c9fb30ff7d7c01b">LLwakeUp</a>(link))
<a name="l00239"></a>00239           <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00240"></a>00240         <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#gaefd78fa2909cf1b98961ebf3e845e7b1">LLresetLineColor</a>(link))
<a name="l00241"></a>00241           <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00242"></a>00242         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245 <span class="comment"></span>
<a name="l00246"></a>00246 <span class="comment">/**</span>
<a name="l00247"></a>00247 <span class="comment"> * This function wakes the line leader to prepare for use.</span>
<a name="l00248"></a>00248 <span class="comment"> * Issuing a command also wakes the line leader as needed.</span>
<a name="l00249"></a>00249 <span class="comment"> * @param link the sensor port number</span>
<a name="l00250"></a>00250 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00251"></a>00251 <span class="comment"> */</span>
<a name="l00252"></a><a class="code" href="group__msll.html#ga3b5fbe1abe3eb0889c9fb30ff7d7c01b">00252</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga3b5fbe1abe3eb0889c9fb30ff7d7c01b">LLwakeUp</a>(tSensors link) {
<a name="l00253"></a>00253   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(link, <span class="charliteral">&#39;P&#39;</span>)) <span class="comment">// Sort by size</span>
<a name="l00254"></a>00254     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00255"></a>00255   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 
<a name="l00258"></a>00258 <span class="comment"></span>
<a name="l00259"></a>00259 <span class="comment">/**</span>
<a name="l00260"></a>00260 <span class="comment"> * This function puts the line leader to sleep conserve power.</span>
<a name="l00261"></a>00261 <span class="comment"> * @param link the sensor port number</span>
<a name="l00262"></a>00262 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00263"></a>00263 <span class="comment"> */</span>
<a name="l00264"></a><a class="code" href="group__msll.html#ga2bbf71694ef338dab472618a6442c429">00264</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga2bbf71694ef338dab472618a6442c429">LLsleep</a>(tSensors link) {
<a name="l00265"></a>00265   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(link, <span class="charliteral">&#39;D&#39;</span>)) <span class="comment">// Sort by size</span>
<a name="l00266"></a>00266     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00267"></a>00267   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00268"></a>00268 }
<a name="l00269"></a>00269 
<a name="l00270"></a>00270 <span class="comment"></span>
<a name="l00271"></a>00271 <span class="comment">/**</span>
<a name="l00272"></a>00272 <span class="comment"> * the function toggles from dark line on light to light line on dark and back.</span>
<a name="l00273"></a>00273 <span class="comment"> * @param link the sensor port number</span>
<a name="l00274"></a>00274 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00275"></a>00275 <span class="comment"> */</span>
<a name="l00276"></a><a class="code" href="group__msll.html#gad94d0f9fc1c628d9e1a8fe598d64302b">00276</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#gad94d0f9fc1c628d9e1a8fe598d64302b">LLinvertLineColor</a>(tSensors link) {
<a name="l00277"></a>00277   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(link, <span class="charliteral">&#39;I&#39;</span>)) <span class="comment">// invert motors</span>
<a name="l00278"></a>00278     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00279"></a>00279   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00280"></a>00280 }
<a name="l00281"></a>00281 
<a name="l00282"></a>00282 <span class="comment"></span>
<a name="l00283"></a>00283 <span class="comment">/**</span>
<a name="l00284"></a>00284 <span class="comment"> * the function resets to default of sensing a dark line on light background</span>
<a name="l00285"></a>00285 <span class="comment"> * @param link the sensor port number</span>
<a name="l00286"></a>00286 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00287"></a>00287 <span class="comment"> */</span>
<a name="l00288"></a><a class="code" href="group__msll.html#gaefd78fa2909cf1b98961ebf3e845e7b1">00288</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#gaefd78fa2909cf1b98961ebf3e845e7b1">LLresetLineColor</a>(tSensors link) {
<a name="l00289"></a>00289   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(link, <span class="charliteral">&#39;R&#39;</span>)) <span class="comment">// reset the color to black</span>
<a name="l00290"></a>00290     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00291"></a>00291   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00292"></a>00292 }
<a name="l00293"></a>00293 
<a name="l00294"></a>00294 <span class="comment"></span>
<a name="l00295"></a>00295 <span class="comment">/**</span>
<a name="l00296"></a>00296 <span class="comment"> * This function takes a snapshot of the line under the sensor</span>
<a name="l00297"></a>00297 <span class="comment"> * and tracks that position in subsequent tracking operations.</span>
<a name="l00298"></a>00298 <span class="comment"> * Also this function will set inversion if it sees white line</span>
<a name="l00299"></a>00299 <span class="comment"> * on dark background</span>
<a name="l00300"></a>00300 <span class="comment"> * @param link the sensor port number</span>
<a name="l00301"></a>00301 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00302"></a>00302 <span class="comment"> */</span>
<a name="l00303"></a><a class="code" href="group__msll.html#ga71dbb04b90ec6f5c90c34b5db4c638d5">00303</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga71dbb04b90ec6f5c90c34b5db4c638d5">LLtakeSnapshot</a>(tSensors link) {
<a name="l00304"></a>00304   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(link, <span class="charliteral">&#39;S&#39;</span>)) <span class="comment">// take a snapshot</span>
<a name="l00305"></a>00305     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00306"></a>00306   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00307"></a>00307 }
<a name="l00308"></a>00308 
<a name="l00309"></a>00309 <span class="comment"></span>
<a name="l00310"></a>00310 <span class="comment">/**</span>
<a name="l00311"></a>00311 <span class="comment"> * This function calibrates the white threshold for each sensor in the array.</span>
<a name="l00312"></a>00312 <span class="comment"> * Place the array over the white surface with all sensors on the white</span>
<a name="l00313"></a>00313 <span class="comment"> * area.  Execute this command to set white values internally.</span>
<a name="l00314"></a>00314 <span class="comment"> * @param link the sensor port number</span>
<a name="l00315"></a>00315 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00316"></a>00316 <span class="comment"> */</span>
<a name="l00317"></a><a class="code" href="group__msll.html#ga780835bc9c4f659670ac26a992896ac7">00317</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga780835bc9c4f659670ac26a992896ac7">LLcalWhite</a>(tSensors link) {
<a name="l00318"></a>00318   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(link, <span class="charliteral">&#39;W&#39;</span>)) <span class="comment">// calibrate white</span>
<a name="l00319"></a>00319     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00320"></a>00320   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00321"></a>00321 }
<a name="l00322"></a>00322 
<a name="l00323"></a>00323 <span class="comment"></span>
<a name="l00324"></a>00324 <span class="comment">/**</span>
<a name="l00325"></a>00325 <span class="comment"> * This function calibrates the black threshold for each sensor in the array.</span>
<a name="l00326"></a>00326 <span class="comment"> * Place the array over the white surface with all sensors on the black</span>
<a name="l00327"></a>00327 <span class="comment"> * area.  Execute this command to set black values internally.</span>
<a name="l00328"></a>00328 <span class="comment"> * @param link the sensor port number</span>
<a name="l00329"></a>00329 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00330"></a>00330 <span class="comment"> */</span>
<a name="l00331"></a><a class="code" href="group__msll.html#ga9441ee5facb3b5a93d35fd47624b996c">00331</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga9441ee5facb3b5a93d35fd47624b996c">LLcalBlack</a>(tSensors link) {
<a name="l00332"></a>00332   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga2d006a5dfeb2fe7485f2175b5832b70c">_lineLeader_cmd</a>(link, <span class="charliteral">&#39;B&#39;</span>)) <span class="comment">// calibrate black</span>
<a name="l00333"></a>00333     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00334"></a>00334   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00335"></a>00335 }
<a name="l00336"></a>00336 
<a name="l00337"></a>00337 <span class="comment"></span>
<a name="l00338"></a>00338 <span class="comment">/**</span>
<a name="l00339"></a>00339 <span class="comment"> * The set point is used by internally (or externally) by the sensor to</span>
<a name="l00340"></a>00340 <span class="comment"> * determine the middle of the sensor over a line.  This value is compared to</span>
<a name="l00341"></a>00341 <span class="comment"> * the average value to help the robot know if it is left or right of center.</span>
<a name="l00342"></a>00342 <span class="comment"> * @param link the sensor port number</span>
<a name="l00343"></a>00343 <span class="comment"> * @param data - the value to set the set point to</span>
<a name="l00344"></a>00344 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00345"></a>00345 <span class="comment"> */</span>
<a name="l00346"></a><a class="code" href="group__msll.html#ga48b8ab2daaa7afede45d1501933824f0">00346</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga48b8ab2daaa7afede45d1501933824f0">LLsetPoint</a>(tSensors link, ubyte data){
<a name="l00347"></a>00347         <span class="keywordflow">return</span> <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(link, <a class="code" href="group__msll.html#ga71b745ac640e505f3d1b16c9676d80b7">LL_SETPOINT</a>, data);
<a name="l00348"></a>00348 }
<a name="l00349"></a>00349 
<a name="l00350"></a>00350 <span class="comment"></span>
<a name="l00351"></a>00351 <span class="comment">/**</span>
<a name="l00352"></a>00352 <span class="comment"> * This function reads the setpoint value from the sensor</span>
<a name="l00353"></a>00353 <span class="comment"> * @param link the sensor port number</span>
<a name="l00354"></a>00354 <span class="comment"> * @return value of setpoint</span>
<a name="l00355"></a>00355 <span class="comment"> */</span>
<a name="l00356"></a><a class="code" href="group__msll.html#ga8b142f1b378d3cecbdd5e4b5a2a7d788">00356</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga48b8ab2daaa7afede45d1501933824f0">LLsetPoint</a>(tSensors link){
<a name="l00357"></a>00357         <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#gacc1f77e986571b86ba33032b50cb455f">LL_KP_VALUE</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>);
<a name="l00358"></a>00358         <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00359"></a>00359 }
<a name="l00360"></a>00360 
<a name="l00361"></a>00361 
<a name="l00362"></a>00362 <span class="comment">/*</span>
<a name="l00363"></a>00363 <span class="comment"> * The following parameters (kp,ki,kd) are specific</span>
<a name="l00364"></a>00364 <span class="comment"> * to your robot. They will change based on robot design,</span>
<a name="l00365"></a>00365 <span class="comment"> * it&#39;s traction with mat, weight, wheel size, wheel spacing,</span>
<a name="l00366"></a>00366 <span class="comment"> * sensor distance from wheels, etc, etc.</span>
<a name="l00367"></a>00367 <span class="comment"> *</span>
<a name="l00368"></a>00368 <span class="comment"> * Tune them as best as you can for your robot.&lt;br&gt;</span>
<a name="l00369"></a>00369 <span class="comment"> * Note, in general,&lt;br&gt;</span>
<a name="l00370"></a>00370 <span class="comment"> *  kp will be a high value near 1.0 (30/32)&lt;br&gt;</span>
<a name="l00371"></a>00371 <span class="comment"> *  ki will be zero or very low value (0.01), and&lt;br&gt;</span>
<a name="l00372"></a>00372 <span class="comment"> *  kd will be a low value near 0.25 (8/32)&lt;br&gt;</span>
<a name="l00373"></a>00373 <span class="comment"> *</span>
<a name="l00374"></a>00374 <span class="comment"> * If you wish to learn more about Kp, Ki, Kd, please</span>
<a name="l00375"></a>00375 <span class="comment"> * read the user guide.&lt;br&gt;</span>
<a name="l00376"></a>00376 <span class="comment"> * An excellent explanation of PID is also offered at:</span>
<a name="l00377"></a>00377 <span class="comment"> * http://en.wikipedia.org/wiki/PID_controller</span>
<a name="l00378"></a>00378 <span class="comment"> *</span>
<a name="l00379"></a>00379 <span class="comment"> * p:25/32,i:0, d:8/32</span>
<a name="l00380"></a>00380 <span class="comment"> */</span>
<a name="l00381"></a>00381 
<a name="l00382"></a>00382 
<a name="l00383"></a>00383 <span class="comment"></span>
<a name="l00384"></a>00384 <span class="comment">/**</span>
<a name="l00385"></a>00385 <span class="comment"> * Set the &quot;Kp&quot; value for the sensor&#39;s internal PID calculations.&lt;br&gt;</span>
<a name="l00386"></a>00386 <span class="comment"> * This value is usually set close to 1.0  default 25/32&lt;br&gt;</span>
<a name="l00387"></a>00387 <span class="comment"> * EXPECTED VALUES: 0 to 255&lt;br&gt;</span>
<a name="l00388"></a>00388 <span class="comment"> * DEFAULT VALUE: 25&lt;br&gt;</span>
<a name="l00389"></a>00389 <span class="comment"> * EXPECTED FACTORS: 1 to 255&lt;br&gt;</span>
<a name="l00390"></a>00390 <span class="comment"> * DEFAULT FACTOR: 32</span>
<a name="l00391"></a>00391 <span class="comment"> * @param link the sensor port number</span>
<a name="l00392"></a>00392 <span class="comment"> * @param data - the value to set Kp</span>
<a name="l00393"></a>00393 <span class="comment"> * @param factor - the Kp factor where p = Kp/Kpfactor</span>
<a name="l00394"></a>00394 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00395"></a>00395 <span class="comment"> */</span>
<a name="l00396"></a><a class="code" href="group__msll.html#ga023144b86129e6828fa94b757016065f">00396</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga023144b86129e6828fa94b757016065f">LLsetKp</a>(tSensors link, ubyte data, ubyte factor){
<a name="l00397"></a>00397         <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(link, <a class="code" href="group__msll.html#gacc1f77e986571b86ba33032b50cb455f">LL_KP_VALUE</a>, data);
<a name="l00398"></a>00398         <span class="keywordflow">if</span> ( factor == 0 ) factor = 1;
<a name="l00399"></a>00399         <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(link, <a class="code" href="group__msll.html#gada9c6b1576eca1d325b85c40cc7855af">LL_KP_FACTOR</a>, factor);
<a name="l00400"></a>00400   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00401"></a>00401 }
<a name="l00402"></a>00402 
<a name="l00403"></a>00403 <span class="comment"></span>
<a name="l00404"></a>00404 <span class="comment">/**</span>
<a name="l00405"></a>00405 <span class="comment"> * Read the &quot;Kp&quot; value from the sensor.</span>
<a name="l00406"></a>00406 <span class="comment"> * @param link the sensor port number</span>
<a name="l00407"></a>00407 <span class="comment"> * @return Kp value from the sensor</span>
<a name="l00408"></a>00408 <span class="comment"> */</span>
<a name="l00409"></a><a class="code" href="group__msll.html#gaee40b167cd0fcb978895964cbf1d478b">00409</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#gaee40b167cd0fcb978895964cbf1d478b">LLreadKp</a>(tSensors link) {
<a name="l00410"></a>00410         <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#gacc1f77e986571b86ba33032b50cb455f">LL_KP_VALUE</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>);
<a name="l00411"></a>00411         <span class="keywordflow">return</span> (<span class="keywordtype">int</span>) <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00412"></a>00412 }
<a name="l00413"></a>00413 
<a name="l00414"></a>00414 <span class="comment"></span>
<a name="l00415"></a>00415 <span class="comment">/**</span>
<a name="l00416"></a>00416 <span class="comment"> * Read the &quot;Kp factor&quot; value from the sensor.</span>
<a name="l00417"></a>00417 <span class="comment"> * @param link the sensor port number</span>
<a name="l00418"></a>00418 <span class="comment"> * @return Kp factor value from the sensor</span>
<a name="l00419"></a>00419 <span class="comment"> */</span>
<a name="l00420"></a><a class="code" href="group__msll.html#ga49001b6744c482e856fde7283e711e75">00420</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga49001b6744c482e856fde7283e711e75">LLreadKpFactor</a>(tSensors link) {
<a name="l00421"></a>00421         <span class="keywordflow">if</span> (<a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#gada9c6b1576eca1d325b85c40cc7855af">LL_KP_FACTOR</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>))
<a name="l00422"></a>00422                 <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00423"></a>00423         <span class="keywordflow">else</span>
<a name="l00424"></a>00424           <span class="keywordflow">return</span> 0;
<a name="l00425"></a>00425 }
<a name="l00426"></a>00426 
<a name="l00427"></a>00427 <span class="comment"></span>
<a name="l00428"></a>00428 <span class="comment">/**</span>
<a name="l00429"></a>00429 <span class="comment"> * Set the &quot;Ki&quot; value for the sensor&#39;s internal PID calculations.&lt;br&gt;</span>
<a name="l00430"></a>00430 <span class="comment"> * This value is usually set close to 0  default 0/1&lt;br&gt;</span>
<a name="l00431"></a>00431 <span class="comment"> * EXPECTED VALUES: 0 to 255&lt;br&gt;</span>
<a name="l00432"></a>00432 <span class="comment"> * DEFAULT VALUE: 0&lt;br&gt;</span>
<a name="l00433"></a>00433 <span class="comment"> * EXPECTED FACTORS: 1 to 255&lt;br&gt;</span>
<a name="l00434"></a>00434 <span class="comment"> * DEFAULT FACTOR: 1</span>
<a name="l00435"></a>00435 <span class="comment"> * @param link the sensor port number</span>
<a name="l00436"></a>00436 <span class="comment"> * @param data - the value to set Ki</span>
<a name="l00437"></a>00437 <span class="comment"> * @param factor - the Ki factor where i = Ki/Kifactor</span>
<a name="l00438"></a>00438 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00439"></a>00439 <span class="comment"> */</span>
<a name="l00440"></a><a class="code" href="group__msll.html#ga9ca02184d0ee468b2fdd7e537654d7d3">00440</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga9ca02184d0ee468b2fdd7e537654d7d3">LLsetKi</a>(tSensors link, ubyte data, ubyte factor){
<a name="l00441"></a>00441   <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(link, <a class="code" href="group__msll.html#ga828d2ade2893ef6fe4d3da8dcb5085c7">LL_KI_VALUE</a>, data);
<a name="l00442"></a>00442         <span class="keywordflow">if</span> ( factor == 0 ) factor = 1;
<a name="l00443"></a>00443         <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(link, <a class="code" href="group__msll.html#ga1b438aeb7ddc87573bfd9c24ca42458a">LL_KI_FACTOR</a>, factor);
<a name="l00444"></a>00444   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00445"></a>00445 }
<a name="l00446"></a>00446 
<a name="l00447"></a>00447 <span class="comment"></span>
<a name="l00448"></a>00448 <span class="comment">/**</span>
<a name="l00449"></a>00449 <span class="comment"> * Read the &quot;Ki&quot; value from the sensor.</span>
<a name="l00450"></a>00450 <span class="comment"> * @param link the sensor port number</span>
<a name="l00451"></a>00451 <span class="comment"> * @return Ki value from the sensor</span>
<a name="l00452"></a>00452 <span class="comment"> */</span>
<a name="l00453"></a><a class="code" href="group__msll.html#gac090fcc45f5a6c53c94a31d82b61924e">00453</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#gac090fcc45f5a6c53c94a31d82b61924e">LLreadKi</a>(tSensors link) {
<a name="l00454"></a>00454         <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga828d2ade2893ef6fe4d3da8dcb5085c7">LL_KI_VALUE</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>);
<a name="l00455"></a>00455         <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00456"></a>00456 }
<a name="l00457"></a>00457 
<a name="l00458"></a>00458 <span class="comment"></span>
<a name="l00459"></a>00459 <span class="comment">/**</span>
<a name="l00460"></a>00460 <span class="comment"> * Read the &quot;Ki factor&quot; value from the sensor.</span>
<a name="l00461"></a>00461 <span class="comment"> * @param link the sensor port number</span>
<a name="l00462"></a>00462 <span class="comment"> * @return Ki factor value from the sensor</span>
<a name="l00463"></a>00463 <span class="comment"> */</span>
<a name="l00464"></a><a class="code" href="group__msll.html#ga49d4b5bed7383b1ca1d3b45860dec496">00464</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga49d4b5bed7383b1ca1d3b45860dec496">LLreadKiFactor</a>(tSensors link) {
<a name="l00465"></a>00465         <span class="keywordflow">if</span> (<a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga1b438aeb7ddc87573bfd9c24ca42458a">LL_KI_FACTOR</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>))
<a name="l00466"></a>00466           <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00467"></a>00467         <span class="keywordflow">else</span>
<a name="l00468"></a>00468           <span class="keywordflow">return</span> 0;
<a name="l00469"></a>00469 }
<a name="l00470"></a>00470 
<a name="l00471"></a>00471 <span class="comment"></span>
<a name="l00472"></a>00472 <span class="comment">/**</span>
<a name="l00473"></a>00473 <span class="comment"> * Set the &quot;Kd&quot; value for the sensor&#39;s internal PID calculations.&lt;br&gt;</span>
<a name="l00474"></a>00474 <span class="comment"> * This value is usually set lower to stabilize default 8/32&lt;br&gt;</span>
<a name="l00475"></a>00475 <span class="comment"> * EXPECTED VALUES: 0 to 255&lt;br&gt;</span>
<a name="l00476"></a>00476 <span class="comment"> * DEFAULT VALUE: 8&lt;br&gt;</span>
<a name="l00477"></a>00477 <span class="comment"> * EXPECTED VALUES: 1 to 255&lt;br&gt;</span>
<a name="l00478"></a>00478 <span class="comment"> * DEFAULT FACTOR: 32</span>
<a name="l00479"></a>00479 <span class="comment"> * @param link the sensor port number</span>
<a name="l00480"></a>00480 <span class="comment"> * @param data - the value to set Kd</span>
<a name="l00481"></a>00481 <span class="comment"> * @param factor - the Kd factor where d = Kd/Kdfactor</span>
<a name="l00482"></a>00482 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00483"></a>00483 <span class="comment"> */</span>
<a name="l00484"></a><a class="code" href="group__msll.html#ga5e59a3463a3e8b2665e6b3555da8f93d">00484</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga5e59a3463a3e8b2665e6b3555da8f93d">LLsetKd</a>(tSensors link, ubyte data, ubyte factor){
<a name="l00485"></a>00485   <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(link, <a class="code" href="group__msll.html#gaa6ab601259447a08cb199b0c93c4f398">LL_KD_VALUE</a>, data);
<a name="l00486"></a>00486         <span class="keywordflow">if</span> ( factor == 0 ) factor = 1;
<a name="l00487"></a>00487         <a class="code" href="group__msll.html#ga78825ff1e7aa83f16529ae1461160da5">_lineLeader_write</a>(link, <a class="code" href="group__msll.html#ga92eb450c20cd134bc90ff6ff2f6347a1">LL_KD_FACTOR</a>, factor);
<a name="l00488"></a>00488   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00489"></a>00489 }
<a name="l00490"></a>00490 
<a name="l00491"></a>00491 <span class="comment"></span>
<a name="l00492"></a>00492 <span class="comment">/**</span>
<a name="l00493"></a>00493 <span class="comment"> * Read the &quot;Kd&quot; value from the sensor.</span>
<a name="l00494"></a>00494 <span class="comment"> * @param link the sensor port number</span>
<a name="l00495"></a>00495 <span class="comment"> * @return Kd value from the sensor</span>
<a name="l00496"></a>00496 <span class="comment"> */</span>
<a name="l00497"></a><a class="code" href="group__msll.html#ga2d9d9c3cfd5dd9be7bb4f9e57408fbd7">00497</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga2d9d9c3cfd5dd9be7bb4f9e57408fbd7">LLreadKd</a>(tSensors link) {
<a name="l00498"></a>00498         <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#gaa6ab601259447a08cb199b0c93c4f398">LL_KD_VALUE</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>);
<a name="l00499"></a>00499         <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00500"></a>00500 }
<a name="l00501"></a>00501 
<a name="l00502"></a>00502 <span class="comment"></span>
<a name="l00503"></a>00503 <span class="comment">/**</span>
<a name="l00504"></a>00504 <span class="comment"> * Read the &quot;Kd factor&quot; value from the sensor.</span>
<a name="l00505"></a>00505 <span class="comment"> * @param link the sensor port number</span>
<a name="l00506"></a>00506 <span class="comment"> * @return Kd factor value from the sensor</span>
<a name="l00507"></a>00507 <span class="comment"> */</span>
<a name="l00508"></a><a class="code" href="group__msll.html#ga8d6b35d47284e3ee40b68a490ad71ced">00508</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga8d6b35d47284e3ee40b68a490ad71ced">LLreadKdFactor</a>(tSensors link) {
<a name="l00509"></a>00509         <span class="keywordflow">if</span> (<a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga92eb450c20cd134bc90ff6ff2f6347a1">LL_KD_FACTOR</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>))
<a name="l00510"></a>00510           <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00511"></a>00511         <span class="keywordflow">else</span>
<a name="l00512"></a>00512           <span class="keywordflow">return</span> 0;
<a name="l00513"></a>00513 }
<a name="l00514"></a>00514 
<a name="l00515"></a>00515 <span class="comment"></span>
<a name="l00516"></a>00516 <span class="comment">/**</span>
<a name="l00517"></a>00517 <span class="comment"> * Read the &quot;Steering&quot; value from the sensor.  This value is calculated internally</span>
<a name="l00518"></a>00518 <span class="comment"> * and can directly be used to set turning values for the robot&#39;s motors.&lt;br&gt;</span>
<a name="l00519"></a>00519 <span class="comment"> * EXPECTED VALUES: -100 to 100 (-101=ERROR)</span>
<a name="l00520"></a>00520 <span class="comment"> * @param link the sensor port number (range: -100 to 100)</span>
<a name="l00521"></a>00521 <span class="comment"> * @return steering value from the sensor, -101 for error</span>
<a name="l00522"></a>00522 <span class="comment"> */</span>
<a name="l00523"></a><a class="code" href="group__msll.html#ga5c46604095f77a86983b7aeaf22200dc">00523</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga5c46604095f77a86983b7aeaf22200dc">LLreadSteering</a>(tSensors link) {
<a name="l00524"></a>00524         <span class="keywordflow">if</span> (<a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga85a98047cb31c3c285f3a6d3f4db060a">LL_READ_STEERING</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>))
<a name="l00525"></a>00525           <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)(0xFF &amp; <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>);
<a name="l00526"></a>00526         <span class="keywordflow">else</span>
<a name="l00527"></a>00527           <span class="keywordflow">return</span> -101;
<a name="l00528"></a>00528 }
<a name="l00529"></a>00529 
<a name="l00530"></a>00530 <span class="comment"></span>
<a name="l00531"></a>00531 <span class="comment">/**</span>
<a name="l00532"></a>00532 <span class="comment"> * Read the Weighted &quot;Average&quot; value from the sensor.  This value is calculated</span>
<a name="l00533"></a>00533 <span class="comment"> * internally by the sensor where each of the eight sensors is either triggered or not</span>
<a name="l00534"></a>00534 <span class="comment"> * and multiplied by a a factor to help determine if the line is left, right or</span>
<a name="l00535"></a>00535 <span class="comment"> * on center of the line (according to the set point).&lt;br&gt;</span>
<a name="l00536"></a>00536 <span class="comment"> * EXPECTED VALUES: 0-80 (-1=ERROR)&lt;br&gt;</span>
<a name="l00537"></a>00537 <span class="comment"> * &lt;pre&gt; SENSOR:       0    1    2    3    4    5    6    7</span>
<a name="l00538"></a>00538 <span class="comment"> * MULTIPLIER:  10   20   30   40   50   60   70   80&lt;/pre&gt;</span>
<a name="l00539"></a>00539 <span class="comment"> * FORMULA: Sum(Weighted Values)/Number sensors on line&lt;br&gt;</span>
<a name="l00540"></a>00540 <span class="comment"> * Ex. if sensor 0 and 1 are over a line, the average is:&lt;br&gt;</span>
<a name="l00541"></a>00541 <span class="comment"> *     (10 + 20 + 0 + 0 + 0 + 0 + 0 + 0)/2 = 15&lt;br&gt;</span>
<a name="l00542"></a>00542 <span class="comment"> *     in this case 30 &lt; 45 (set point) so the bot is left of center</span>
<a name="l00543"></a>00543 <span class="comment"> * @param link the sensor port number</span>
<a name="l00544"></a>00544 <span class="comment"> * @return average sensor value or -1 for error</span>
<a name="l00545"></a>00545 <span class="comment"> */</span>
<a name="l00546"></a><a class="code" href="group__msll.html#ga9a35e15add220ed326ca7520ffe65e6c">00546</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga9a35e15add220ed326ca7520ffe65e6c">LLreadAverage</a>(tSensors link) {
<a name="l00547"></a>00547         <span class="keywordflow">if</span> (<a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga1638f7ba693960a75abf313a7344a9ee">LL_READ_AVERAGE</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>))
<a name="l00548"></a>00548           <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00549"></a>00549         <span class="keywordflow">else</span>
<a name="l00550"></a>00550           <span class="keywordflow">return</span> -1;
<a name="l00551"></a>00551 }
<a name="l00552"></a>00552 
<a name="l00553"></a>00553 <span class="comment"></span>
<a name="l00554"></a>00554 <span class="comment">/**</span>
<a name="l00555"></a>00555 <span class="comment"> * Read a ubyte with each bit equal to a sensor.&lt;br&gt;</span>
<a name="l00556"></a>00556 <span class="comment"> * 1 = Line&lt;br&gt;</span>
<a name="l00557"></a>00557 <span class="comment"> * 0 = No Line&lt;br&gt;</span>
<a name="l00558"></a>00558 <span class="comment"> * &lt;pre&gt; SENSOR:      0    1    2    3    4    5    6    7</span>
<a name="l00559"></a>00559 <span class="comment"> * MULTIPLIER:  1    2    4    8    16   32   64   128&lt;/pre&gt;</span>
<a name="l00560"></a>00560 <span class="comment"> * To determine if a given sensor is over a line or not, use binary math</span>
<a name="l00561"></a>00561 <span class="comment"> * to test each bit.&lt;br&gt;</span>
<a name="l00562"></a>00562 <span class="comment"> * A returned value of 3 means sensor 0 and 1 are over a line.</span>
<a name="l00563"></a>00563 <span class="comment"> * @param link the sensor port number</span>
<a name="l00564"></a>00564 <span class="comment"> * @return RESULT value from the sensor with 8 bits of data; NO ERROR CODE</span>
<a name="l00565"></a>00565 <span class="comment"> */</span>
<a name="l00566"></a><a class="code" href="group__msll.html#ga7dd78212c25b63c0349b8f4c61e11e1b">00566</a> <span class="keywordtype">int</span> <a class="code" href="group__msll.html#ga7dd78212c25b63c0349b8f4c61e11e1b">LLreadResult</a>(tSensors link) {
<a name="l00567"></a>00567   <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga12ad5be14508319b2bfc8290b41ad886">LL_READ_RESULT</a>, <a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>);
<a name="l00568"></a>00568   <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)<a class="code" href="group__msll.html#ga212a936c0d0cc14338cd1152384c4885">oneByte</a>;
<a name="l00569"></a>00569 }
<a name="l00570"></a>00570 
<a name="l00571"></a>00571 <span class="comment"></span>
<a name="l00572"></a>00572 <span class="comment">/**</span>
<a name="l00573"></a>00573 <span class="comment"> * Read the &quot;Raw Sensor&quot; values from the Line Leader.  Amount of light or dark</span>
<a name="l00574"></a>00574 <span class="comment"> * each sensor sees.  Typically between 0-20.  0=black, 100=white</span>
<a name="l00575"></a>00575 <span class="comment"> * @param link the sensor port number</span>
<a name="l00576"></a>00576 <span class="comment"> * @param &amp;pMsg is 8 bytes returned.  One for each sensor with raw value.</span>
<a name="l00577"></a>00577 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00578"></a>00578 <span class="comment"> */</span>
<a name="l00579"></a><a class="code" href="group__msll.html#ga60491a411576c00b70909e1f295919db">00579</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga60491a411576c00b70909e1f295919db">LLreadSensorRaw</a>(tSensors link, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pMsg) {
<a name="l00580"></a>00580         <span class="keywordflow">return</span> <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga5638e005055b1df5e595734a42c4b179">LL_SENSOR_RAW</a>, 8, pMsg);
<a name="l00581"></a>00581 }
<a name="l00582"></a>00582 
<a name="l00583"></a>00583 <span class="comment"></span>
<a name="l00584"></a>00584 <span class="comment">/**</span>
<a name="l00585"></a>00585 <span class="comment"> * Read the uncalibrated sensor values from the Line Leader.  Each sensor returns a 16 bit</span>
<a name="l00586"></a>00586 <span class="comment"> * value.</span>
<a name="l00587"></a>00587 <span class="comment"> * @param link the sensor port number</span>
<a name="l00588"></a>00588 <span class="comment"> * @param sensorValues is 8 bytes returned.  One for each sensor with raw value.</span>
<a name="l00589"></a>00589 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00590"></a>00590 <span class="comment"> */</span>
<a name="l00591"></a><a class="code" href="group__msll.html#ga9c243c81526226b5666b5d14a5fc8e59">00591</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga9c243c81526226b5666b5d14a5fc8e59">LLreadSensorUncalibrated</a> (tSensors link, <a class="code" href="group__common.html#ga79eb917b5a56f0d0e7cf94886c6ac25c">tIntArray</a> &amp;sensorValues) {
<a name="l00592"></a>00592   <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> sensorData;
<a name="l00593"></a>00593 
<a name="l00594"></a>00594   <span class="keywordflow">if</span> (!<a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#gad0456ad794e3fa5deb85f288315c4d49">LL_SENSOR_UNCAL</a>, 16, sensorData)) {
<a name="l00595"></a>00595     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00596"></a>00596   }
<a name="l00597"></a>00597 
<a name="l00598"></a>00598   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 8; i++) {
<a name="l00599"></a>00599     sensorValues[i] = (0xFF &amp; sensorData[(i*2)]) + ((0xFF &amp; sensorData[((i*2)+1)]) &lt;&lt; 8);
<a name="l00600"></a>00600   }
<a name="l00601"></a>00601 
<a name="l00602"></a>00602   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00603"></a>00603 }
<a name="l00604"></a>00604 
<a name="l00605"></a>00605 <span class="comment"></span>
<a name="l00606"></a>00606 <span class="comment">/**</span>
<a name="l00607"></a>00607 <span class="comment"> * Read the &quot;White Threshold&quot; values from the Line Leader for each sensor.&lt;br&gt;</span>
<a name="l00608"></a>00608 <span class="comment"> * Each of the eight sensors has a value.  Raw values greater then this threshold</span>
<a name="l00609"></a>00609 <span class="comment"> * equal white (area).&lt;br&gt;</span>
<a name="l00610"></a>00610 <span class="comment"> * The values are set when calibrating the white points for the sensor.</span>
<a name="l00611"></a>00611 <span class="comment"> * @param link the sensor port number</span>
<a name="l00612"></a>00612 <span class="comment"> * @param &amp;pMsg is 8 bytes returned.  One for each sensor with Threshold.</span>
<a name="l00613"></a>00613 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00614"></a>00614 <span class="comment"> */</span>
<a name="l00615"></a><a class="code" href="group__msll.html#ga1aaffb6d171becb4d2cb516077417691">00615</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#ga1aaffb6d171becb4d2cb516077417691">LLreadWhiteThresh</a>(tSensors link, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pMsg) {
<a name="l00616"></a>00616         <span class="keywordflow">return</span> <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga253d9d0e7d4ea08b11dc777088490bc1">LL_WHITE_LIMIT</a>, 8, pMsg);
<a name="l00617"></a>00617 }
<a name="l00618"></a>00618 
<a name="l00619"></a>00619 <span class="comment"></span>
<a name="l00620"></a>00620 <span class="comment">/**</span>
<a name="l00621"></a>00621 <span class="comment"> * Read the &quot;Black Threshold&quot; values from the Line Leader for each sensor.&lt;br&gt;</span>
<a name="l00622"></a>00622 <span class="comment"> * Each of the eight sensors has a value.  Raw values less then this threshold</span>
<a name="l00623"></a>00623 <span class="comment"> * equal black (line).&lt;br&gt;</span>
<a name="l00624"></a>00624 <span class="comment"> * The values are set when calibrating the black points for the sensor.</span>
<a name="l00625"></a>00625 <span class="comment"> * @param link the sensor port number</span>
<a name="l00626"></a>00626 <span class="comment"> * @param &amp;pMsg is 8 bytes returned.  One for each sensor with Threshold.</span>
<a name="l00627"></a>00627 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00628"></a>00628 <span class="comment"> */</span>
<a name="l00629"></a><a class="code" href="group__msll.html#gafe57238ecefde4bc4992c0ff8c77a896">00629</a> <span class="keywordtype">bool</span> <a class="code" href="group__msll.html#gafe57238ecefde4bc4992c0ff8c77a896">LLreadBlackThresh</a>(tSensors link, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;pMsg) {
<a name="l00630"></a>00630         <span class="keywordflow">return</span> <a class="code" href="group__msll.html#ga516ab302bdda4f6159a2ef5ffd6b2f8d">_lineLeader_read</a>(link, <a class="code" href="group__msll.html#ga746144b962d3a52cbf7d507c6be2d4c2">LL_BLACK_LIMIT</a>, 8, pMsg);
<a name="l00631"></a>00631 }
<a name="l00632"></a>00632 
<a name="l00633"></a>00633 
<a name="l00634"></a>00634 <span class="preprocessor">#endif // __MSLL_H__</span>
<a name="l00635"></a>00635 <span class="preprocessor"></span>
<a name="l00636"></a>00636 <span class="comment">/*</span>
<a name="l00637"></a>00637 <span class="comment"> * $Id: mindsensors-lineleader.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00638"></a>00638 <span class="comment"> */</span>
<a name="l00639"></a>00639 <span class="comment">/* @} */</span>
<a name="l00640"></a>00640 <span class="comment">/* @} */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:43 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
